<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './resize'

const animationDuration = 6000

export default {
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '220px'
        },
        chartData: {
            type: Array,
            // required: true
        }
    },
    data() {
        return {
            chart: null,
        }
    },
    watch: {
        chartData: {
            deep: true,
            handler(val) {
                // this.setOptions(val)
            }
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$el, 'macarons')
            // this.setOptions(this.chartData)
            this.setOptions()
        },
        setOptions(numData) {
            let isData = [{
                xAxis: 0,
                yAxis: 11,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            }, {
                xAxis: 1,
                yAxis: 12,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            },
            {
                xAxis: 2,
                yAxis: 13,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            }, {
                xAxis: 3,
                yAxis: 14,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            }, {
                xAxis: 4,
                yAxis: 15,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            }, {
                xAxis: 5,
                yAxis: 16,
                // symbol: 'image://https://longduxing.cn/assets/images/c4814be7309811e7b23600163e329925/admin-logo.png'
            }]

            this.chart.setOption({
                tooltip: {
                    trigger: 'axis',
                    axisPointer: { // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                grid: {
                    top: '10%',
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [{
                    type: 'category',
                    data: ['站点1', '站点2', '站点3', '站点4', '站点5', '站点6'],
                    axisTick: {
                        alignWithLabel: true
                    }
                }],
                yAxis: [{
                    type: 'value',
                    axisTick: {
                        show: false
                    }
                }],
                series: [{
                    name: '',
                    type: 'bar',
                    barWidth: '30',
                    data: [0, 0, 0, 0, 0, 0, 0],
                    itemStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [
                                { offset: 0, color: 'rgba(209, 156, 16,0.6)' }, // 0% 处的颜色
                                { offset: 1, color: 'rgba(209, 156, 16,0.1)' } // 100% 处的颜色
                            ],
                            global: false // 缺省为 false
                        },
                    },
                    // markPoint: {
                    //     data: isData,
                    //     symbolSize: [20, 20],
                    //     label: {
                    //         show: false
                    //     }
                    // },

                }],

            })
        }
    }
}
</script>
